package com.bdqn.util;

import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;

import javax.annotation.Resource;

/**
 * MailUtil
 *
 * @author LILIBO
 * @since 2022-05-06
 */
public class MailUtil {

    @Resource
    private static JavaMailSender javaMailSender;

    /**
     * 发送邮件
     *
     * @param to 收件人
     * @param from 寄件人
     * @param subject 主题
     * @param text 内容
     * @return 是否成功
     */
    public static boolean sendMail(String to, String from, String subject, String text) {

        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        simpleMailMessage.setTo(to);
        simpleMailMessage.setFrom(from);
        simpleMailMessage.setSubject(subject);
        simpleMailMessage.setText(text);
        javaMailSender.send(simpleMailMessage);
        return true;
    }

}
